﻿using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using DaaseVarmer.domain;
using DaaseVarmer.helperClasses.HardwareInterface;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
using DaaseVarmer.webserver.impl;
using DaaseVarmer.helperClasses;
using DaaseVarmer.webserver.framework;
using DaaseVarmer.RemoteControl;

namespace DaaseVarmer
{
    /* 
     * Initiating class
     */
    public class Program
    {


        public static MainLoop mainLoop = new MainLoop();
        public static SdAccess SdAccess = new SdAccess();
        public static WebServer webserver = new WebServer(80);
        public static RemoteControlListener remoteControlListener = new RemoteControlListener(35474, new RemoteControlStub());
        

        public static void Main()
        {
            Debug.EnableGCMessages(true);
            EnableDHCP();
            InitiateAndStartThreads();
        }

        private static void EnableDHCP()
        {
            Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].EnableDhcp();
         
        }

        private static void InitiateAndStartThreads()
        {

            Thread webServerThread = new Thread(new ThreadStart(delegate() { webserver.listenForRequest(); }));
            Thread remoteControlThread = new Thread(new ThreadStart(delegate() { remoteControlListener.Listen(); }));
            Thread mainLoopThread = new Thread(new ThreadStart(delegate() { mainLoop.Run(); }));

            webServerThread.Start();
            remoteControlThread.Start();
            mainLoopThread.Start();

        }
    }
}
